package com.ouyu.factory.support;

import com.ouyu.factory.config.BeanDefinition;
import com.ouyu.factory.BeanFactory;

/**
 * @Author: hz21056677
 * @Description:
 * @Date: Created in 17:30 2021/6/3
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String name) {
        Object bean = getSingleton(name);
        if(bean != null){
            return bean;
        }
        BeanDefinition definition = getBeanDefinition(name);
        return createBean(name,definition,null);
    }

    @Override
    public Object getBean(String name, Object... args) {
        Object bean = getSingleton(name);
        if(bean != null){
            return bean;
        }
        BeanDefinition definition = getBeanDefinition(name);
        return createBean(name,definition,args);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);
    protected abstract Object createBean(String beanName,BeanDefinition definition,Object[] args);
}
